package com.codelab.statemachine.service;

import cn.hutool.core.util.NumberUtil;
import com.codelab.statemachine.task.ProgressPOJO;
import com.codelab.statemachine.task.TaskProgress;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class Demo2Progress implements TaskProgress {
    private double i = 0;

    @Override
    public String getTaskCode() {
        return "demo2";
    }

    @Override
    public ProgressPOJO getProgress(Map map) {
        i+=10;
        if(i>100){
            i=100;
        }
        ProgressPOJO pojo = new ProgressPOJO();
        pojo.setCode("0");
        pojo.setProgress(NumberUtil.div(i,100));
        if(NumberUtil.equals(pojo.getProgress(),1)){
            i=0;
            pojo.setDone(true);
        }
        return pojo;
    }
}
